<template>
  <div class="_wz_cent_main _wz_hiddenDangersTroubleshoot">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>

        <FormItem label="风险等级">
          <i-select v-model.number="formDataSearch.riskItemGrade" filterable placeholder="请选择风险等级" clearable>
            <Option :value="1">低风险</Option>
            <Option :value="2">一般风险</Option>
            <Option :value="3">较大风险</Option>
            <Option :value="4">重大风险</Option>
          </i-select>
        </FormItem>
        <FormItem label="整改状态">
          <i-select v-model.number="formDataSearch.riskHandleState" filterable placeholder="请选择整改状态" clearable>
            <Option :value="0">未整改</Option>
            <Option :value="1">已整改</Option>
          </i-select>
        </FormItem>
        <FormItem label="完成时间" v-if="searchType">
          <DatePicker type="daterange" v-model="dateRange" placeholder="请选择完成时间" style="width:96%"></DatePicker>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="success" @click="deriveData">导出</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <Drawer title="整改" v-model="formOperation" width="800" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <hiddenDangersListDealWith v-if="formOperation" :riskListData="riskListData" @closeFun="closeFun"></hiddenDangersListDealWith>
    </Drawer>

  </div>
</template>
<script>


import hiddenDangersListDealWith from "./hiddenDangersListDealWith";
import wzTbale from "../../../components/table/table";

export default {
  components: {
    hiddenDangersListDealWith,//查看详情
    wzTbale,//列表
  },
  data() {
    return {
      searchType:false,//搜索条件
      subDeptList: [],//运输企业
      dateRange: [],//时间范围
      riskListData: {},//

      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      formOperation: false,
      formDataSearch: {riskCheckState:1},//搜索表单数据
      tableData: {
        url: this.apiUrl.webApi + "/safety/risk/riskCheckDetailPageList",//请求地址
        method: 'post',//请求方式
        where: {riskCheckState:1},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '风险项目', width: 140, key: 'riskItemCheckName'},
          {title: '风险内容', minWidth: 260, key: 'riskItemCheckContent'},
          {
            title: '整改状态', key: 'riskItemHandleState',width: 140, render: (h, params) => {
              //（1：低风险，2：一般风险，3：较大风险:，4：重大风险） riskItemGrade;
              var color = '', test = '';
              if (params.row.riskItemHandleState == 0) {
                color = 'warning', test = '未整改';
              } else if (params.row.riskItemHandleState == 1) {
                color = 'primary', test = '已整改';
              }
              return h('Tag', {
                props: {
                  type: 'dot',
                  color: color
                }
              }, test);
            }
          },
          {
            title: '风险等级', key: 'riskItemGrade', width: 140, render: (h, params) => {
              //（1：低风险，2：一般风险，3：较大风险:，4：重大风险） riskItemGrade;
              var color = '', test = '';
              if (params.row.riskItemGrade == 1) {
                color = 'primary', test = '低风险';
              } else if (params.row.riskItemGrade == 2) {
                color = 'success', test = '一般风险';
              } else if (params.row.riskItemGrade == 3) {
                color = 'warning', test = '较大风险';
              } else {
                color = 'error', test = '重大风险';
              }
              return h('Tag', {
                props: {
                  type: 'dot',
                  color: color
                }
              }, test);
            }
          },
          // {title: '管控措施', minWidth: 180, key: 'riskItemControl'},
          // {title: '失控表现', minWidth: 180, key: 'riskItemOutControl'},
          {title: '责任部门', width: 140, key: 'riskCheckDept'},
          {title: '责任人员', width: 100, key: 'riskCheckPerson'},
          {title: '问题描述', width: 160, key: 'riskDescribe'},
          {title: '排查时间', width: 160, key: 'riskItemWhenDate'},
          {title: '完成时间', width: 160, key: 'riskItemCompletionDate'},
          {
            title: '操作', fixed: 'right', width:80,
            render: (h, params) => {
              var operationCertificate = [];

              if (params.row.riskItemHandleState == 0) {
                operationCertificate.push(
                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.riskListData = params.row;
                        this.formOperation = true;
                      }
                    }
                  }, "整改")
                )
              }else{
                operationCertificate.push(
                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.riskListData = params.row;
                        this.formOperation = true;
                      }
                    }
                  }, "查看")
                )
              }

              return operationCertificate;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },

    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    var that = this;

    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })


  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.formDataSearch.riskItemCompletionStartDate = !!this.dateRange[0] ? this.public.timeFormatting(this.dateRange[0], "yyyy-MM-dd") : '';
      this.formDataSearch.riskItemCompletionEndDate = !!this.dateRange[1] ? this.public.timeFormatting(this.dateRange[1], "yyyy-MM-dd") : '';
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //导出
    deriveData() {
      var that = this;
      let formDataSearch = JSON.parse(JSON.stringify(this.formDataSearch));
      that.spinShow = true;
      that.axios.post(that.apiUrl.webApi + "/safety/risk/riskCheckHandleDetailExport", formDataSearch).then(res => {
        that.spinShow = false;
        if (!!res) {
          window.open(that.apiUrl.imgUrl + res.data.data)
        }
      }).catch(err => {
        console.log("失败", err)
      })
    },

    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.formOperation = false;
    },

  },
  watch: {//监听

  },
  props: {//接收来自父组件的数据

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_hiddenDangersTroubleshoot {
  display: flex;
  flex-direction: column;


}
</style>
